package com.tubeonfire.controller;

import java.util.List;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.tubeonfire.entity.Category;
import com.tubeonfire.entity.Channel;
import com.tubeonfire.entity.Playlist;
import com.tubeonfire.entity.Tube;
import com.tubeonfire.model.CategoryModel;
import com.tubeonfire.model.PlaylistModel;
import com.tubeonfire.service.ChannelService;
import com.tubeonfire.service.TubeService;
import com.tubeonfire.util.JavaCacheHandle;

public class ServletContext implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("Stop");
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		System.out.println("Start");
//		JavaCacheHandle.initCache();
//		JavaCacheHandle.removeCache();
//		List<Channel> listChannel = ChannelService.getMostViewdToday();
//		if (listChannel != null && listChannel.size() > 0) {
//			JavaCacheHandle.addChannels(listChannel);
//		}
//
//		List<Tube> listMostViewToday = TubeService.getMostView("today", 6, 1)
//				.getListTube();
//		if (listMostViewToday != null && listMostViewToday.size() > 0) {
//			JavaCacheHandle.addMostViewToday(listMostViewToday);
//		}
//
//		List<Tube> listMostViewAllTime = TubeService.getMostView("all_time", 6,
//				1).getListTube();
//		if (listMostViewAllTime != null && listMostViewAllTime.size() > 0) {
//			JavaCacheHandle.addMostViewAllTime(listMostViewToday);
//		}
//
//		List<Tube> listPopular = TubeService.getMostPopular("all_time");
//		if (listPopular != null && listPopular.size() > 0) {
//			JavaCacheHandle.addPopular(listPopular);
//		}
//
//		List<Tube> listRecent = TubeService.getMostRecent();
//		if (listRecent != null && listRecent.size() > 0) {
//			JavaCacheHandle.addRecent(listRecent);
//		}
//
//		List<Category> listCategory = CategoryModel.all();
//		if (listCategory != null && listCategory.size() > 0) {
//			JavaCacheHandle.addCategory(listCategory);
//		}
//
//		List<Playlist> listPl = PlaylistModel.all();
//		if (listPl != null && listPl.size() > 0) {
//			JavaCacheHandle.addPl(listPl);
//		}
		System.out.println("Done.");
	}
}